/**********************************************************************************************************************
 *
 * Project:    mGameEngine
 * File:       userallocator.h
 * Author:     twoja stara
 * Created on: 2011-04-03
 *
 **********************************************************************************************************************/

#ifndef USERALLOCATOR_H_
#define USERALLOCATOR_H_

#include "../common.h"
#include <NxPhysics.h>

namespace mGameEngine
{
namespace Physics
{

/**
 * Custom allocator for physX.
 * Based on allocator provided by original PhysX SDK.
 */
class UserAllocator : public NxUserAllocator
{
private:
    Lock _allocLock;
    size_t *mMemBlockList;
    NxU32 mMemBlockListSize;
    NxU32 mMemBlockFirstFree;
    NxU32 mMemBlockUsed;
    NxI32 mNbAllocatedBytes;
    NxI32 mHighWaterMark;
    NxI32 mTotalNbAllocs;
    NxI32 mNbAllocs;
    NxI32 mNbReallocs;

public:
    UserAllocator();
    virtual ~UserAllocator();
    void reset();
    void *malloc(size_t size);
    void *malloc(size_t size, NxMemoryType type);
    void *mallocDEBUG(size_t size, const char* file, int line);
    void *mallocDEBUG(size_t size, const char* file, int line, const char* className, NxMemoryType type);
    void *realloc(void* memory, size_t size);
    void free(void* memory);
};

}
}

#endif // USERALLOCATOR_H_
